package com.woniuxy.threeproject.end_water_project_user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.threeproject.end_water_project_user.commons.Result;
import com.woniuxy.threeproject.end_water_project_user.dao.AccountMapper;
import com.woniuxy.threeproject.end_water_project_user.domain.Account;
import com.woniuxy.threeproject.end_water_project_user.domain.form.AccountForm;
import com.woniuxy.threeproject.end_water_project_user.service.IAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 账号表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@RestController
@Slf4j
@RequestMapping("/account")

public class AccountController {

    @Resource
    public IAccountService iAccountService;

    @GetMapping("login")
    public Result login(Long name,String password){
//        此处的name应该是数字，数据库为account
     log.info("获取账户id为{},密码:{}",name,password);
     if(name!=null&&password!=null){
         Account ac = new Account();
         ac.setAccount(name);
         ac.setPassword(password);
         int i = iAccountService.login(ac);
         if(1==i){
             log.info("{}登录成功！",name);
        // 在这里面添加属性,重新查询一次,单纯得到值,看是否为管理员
           Account reac=iAccountService.selectByAccount(name);
           if(1==reac.getGrade()||0==reac.getGrade()){
//             返回值
               log.info("{}登录成功！",name);
               return  Result.success("200","登录成功！");
           }else{
               return  Result.fail("4011","你的权限不够，暂时不能够登录！");
           }
         }else if(2==i){
             return Result.fail("40001","密码不正确，请您修改后密码再登录！");
         }
         log.warn("{}数据库没有找到该用户！",name);
         return Result.fail("40002","该用户没有找到，请您确认后再登录！");

     }else{
         log.warn("后台没有获取到前台传过来的数据！");
         return Result.fail("40003","服务器开小差了！");
     }
    }

//    忘记密码





}

